package cn.gz.demo.ui.tab_fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import cn.gz.demo.R;
import cn.gz.demo.adapter.FragmentTabAdapter;
import cn.gz.demo.databinding.Tab2Binding;

/**
 * @author Liuyz
 * @date 2020/6/1017:32
 */
public class TabFragment extends Fragment {
    private Tab2Binding binding;
    private FragmentTabAdapter adapter;
    public List<Fragment> fragments = new ArrayList<Fragment>();
    private List<String> titles = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.tab_fragment_2, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        titles.clear();
        titles.add("发现");
        titles.add("发现");
        titles.add("发现");
        titles.add("发现");

        fragments.add(new HomeFrament());
        fragments.add(new FoundFragment());
        fragments.add(new MeFragment());
        fragments.add(new MessageFrament());
        adapter = new FragmentTabAdapter(getChildFragmentManager(), fragments, titles);
        binding.tabViewpager.setAdapter(adapter);

        binding.tabTablayout.setupWithViewPager(binding.tabViewpager);
        binding.tabViewpager.setOffscreenPageLimit(fragments.size());

    }
}
